package com.software.lineragent.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import com.software.common.CommonUtils;
import com.software.form.billform.dao.BillFormTransaction;

public class BillFormServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		BillFormTransaction bt = (BillFormTransaction) CommonUtils.getBean("billFormTransaction");
		JSONObject json = CommonUtils.readJSONStringFromRequestBody(request, response);
		try{
			String com = json.getString("com");
			String con = json.getString("con");
			String name = json.getString("name");
			String addr = json.getString("addr");
			String bank = json.getString("bank");
			String account = json.getString("account");
			String vess = json.getString("vess");
			String voy = json.getString("voy");
			String pol = json.getString("pol");
			String pod = json.getString("pod");
			String no = json.getString("no");
			String dp = json.getString("dp");
			String ocean = json.getString("ocean");
			String pou = json.getString("pou");
			String ad = json.getString("ad");
			String iyd = json.getString("iyd");
			String mark = json.getString("mark");
			String cargo = json.getString("cargo");
			String quantity = json.getString("quantity");
			String kg = json.getString("kg");
			String vol = json.getString("vol");
			String agentemail = json.getString("agentemail");
			
			boolean tag  = false;
			tag = bt.add(no, com, name, addr, bank, account, vess, voy, pol, pod, dp, 
					ocean, pou, ad, iyd, mark, cargo, quantity, kg, vol, agentemail);
			if(tag){
				CommonUtils.outputJsonData(1, response);
			}else{
				CommonUtils.outputJsonData(0, response);
			}
		}catch(JSONException je){
			try {
				CommonUtils.outputJsonData(0, response);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
